import Vue from 'vue'
import App from './app.vue'
import store from './store'
import VueRouter from 'vue-router'
import axios from 'axios'
import Test from './components/Test'
import Grid from './components/Grid.vue'
import MoreGrid from './components/MoreGrid.vue'
import Total from './components/Computedprop.vue'
//import Estest from './components/Es.vue'
import child1 from './components/child1.vue'
import child2 from './components/child2.vue'

Vue.use(VueRouter)

Vue.prototype.$axios = axios

const NotFoundComponent = {template:'<p>404页面什么都没有啊</p>'}

const Estest = resolve => require(['./components/Es.vue'], resolve)   //requirejs?

console.log('Estest')
console.log(Estest)

const routes = [
  { path: '/', component: Grid },
  { path: '/moregrid', component: MoreGrid },
  { path: '/foo/:id', name: 'foo', component: Test },
  { path: '/bar',component: Grid ,alias: '/baraa'  },
  { path: '/user/:id', component: Test },
  { path: '/test', component: Test ,children: [{ path: 'child1', component: child1},{ path: 'child2', component: child2}] },
  { path: '/total', component: Total },
  { path: '/estest', component: Estest},
  { path: '*', component: NotFoundComponent }
  ]

const router = new VueRouter({
  mode: 'history',
  routes // （缩写）相当于 routes: routes
})

axios.interceptors.request.use(function (config) {
  // Do something before request is sent
  store.commit('loading')
  return config;
}, function (error) {
  // Do something with request error
  return Promise.reject(error);
});

axios.interceptors.response.use(function (response) {
  // Do something before request is sent
  store.commit('loading')
  return response;
}, function (error) {
  // Do something with request error
  return Promise.reject(error);
});



console.log('new vue')

const app = new Vue({
  router,
  el: '#haha',
  store,
  render: (h) => h(App)
})

console.dir(app);
